package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;



import sjtu.ist.warehouse4ws.model.Functions;
import sjtu.ist.warehouse4ws.service.FunctionsService;



import com.opensymphony.xwork2.ActionSupport;

public class ShowFunctions extends ActionSupport{
	private List <Functions> fList=new ArrayList<Functions> ();
	private FunctionsService fService;
	
	private String funid;
	
	public String getFunid() {
		return funid;
	}

	public void setFunid(String funid) {
		this.funid = funid;
	}

	public void setFunctionsService(FunctionsService fService) {
		this.fService = fService;
	}
	
	public String showFunctions(){
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.funid=request.getParameter("cid");
		this.fList=fService.getFunctionsbyFunctionId(funid);
		System.out.print(fList.size());
		return SUCCESS;
	}
	
	@JSON(name="totalFunctions")	
	public int getTotalFunctions() {
		return this.fList.size();
	}
    
	@JSON(name="Functions")	
	public List<Functions> getFunctionsList() {
		return this.fList;
	}

}
